package com.rd.student.ruanjian.class4.zhouzihe.day18;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class TestPrint {
    public static void main(String[] args) throws Exception {


        FileInputStream fis = new FileInputStream("in.txt");
        System.setIn(fis);

        Scanner scanner = new Scanner(System.in);
        StringBuilder builder = new StringBuilder();
        while (scanner.hasNext()) {
            builder.append(scanner.nextLine() +"\n");
        }
        System.out.println(builder);
        PrintStream ps = new PrintStream(new FileOutputStream("out.txt"));
        System.setOut(ps);
        System.out.println(builder);
        System.out.println("hello out txt");
        ps.close();
        fis.close();

    }

    public static void testOut() throws Exception {

    }

    public static void test() throws Exception {

        FileOutputStream fos = new FileOutputStream("streamPrint.txt");
        PrintStream ps = new PrintStream(fos);
        ps.println("hello PrintStream");
        //在使用处理流时，只要关闭处理流即可，系统会自动关闭处理流包装的节点流
        ps.close();
    }
}

